import { stringify } from 'query-string';
import axios from 'axios';
import { handleHttpResult, handleResult } from './requestHandler';

const TOKEN = {
  'DAIWAN-API-TOKEN': '78710-B0810-777C7-C9A85',
};

function post(url, data) {
  return axios({
    method: 'POST',
    url,
    data: stringify(data),
    credentials: 'same-origin',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  })
  .then(handleHttpResult)
  .then(handleResult);
}

function get(url) {
  return axios.get(url, { headers: TOKEN })
  .then(handleHttpResult)
  .then(handleResult);
}

export default {
  get,
  post,
};
